home *** CD-ROM | disk | FTP | other *** search
- /* FILE: Num2PStr.c
- Creates a pascal string representation of a given
- type of number, returning TRUE if it fails to do so. */
- #include "PStrLib.h"
-
- Num2PStr(type, numPtr, pStr, format, places)
- int type; /* type of variable pointed at bt numPtr */
- void *numPtr; /* size of *numPtr depends on type */
- register char *pStr; /* points to a PASCAL string */
- int format; /* specifies Decimal or Scientific notation */
- int places; /* # of digits to right of Decimal point */
- {
- auto Decimal _Decimal_;
- auto DecForm _DecForm_;
- register int n = 1;
-
- /* NOTE: When Dec2Str() fails, it sets pStr == '?'. The most common
- cause of failure is trying to convert a large number to
- DEC string format using a large places value. The do-while
- loop below catches such failures and fixes them by changing
- the format to SCI which virtually never fails (See the Apple
- Numerics Manual for more details). */
- do {
- _DecForm_.style = n > 0 ? format : FLOATDECIMAL;
- _DecForm_.digits = format == FLOATDECIMAL ? places + 1 : places;
- fp68k(&_DecForm_, numPtr, &_Decimal_, type + FOB2D);
- Dec2Str(_DecForm_, &_Decimal_, pStr);
- } while (pStr[1] == '?' && --n >= 0);
- return(pStr[1] == '?'); /* Returns TRUE if Dec2Str() FAILED */
- }